//index.js
//获取应用实例
const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    loadingHidden: true,
    currentTabsIndex: 0,
    index: 1,
    num: 1,
    inputText: "",
    time: "",
    fishishTime: "",
    state: "",
    orderList: [],
    finishList: [],
    receiveUserId:0,
    current:0,
    height: wx.getSystemInfoSync().windowHeight
    
  },
  toOrder: function () {
    wx.switchTab({
      url: '../order/order',
    })
  },
  // 详情页
  detail: function (e) {
    var index = e.currentTarget.dataset.id;
    var status = e.currentTarget.dataset.status;
    var receiveUserIdArray = e.currentTarget.dataset.array;
    var publishId = e.currentTarget.dataset.publish;
    var receiveUserId = e.currentTarget.dataset.receiveuserid;
    console.log(receiveUserIdArray);
    var array = JSON.stringify(receiveUserIdArray)
    console.log(receiveUserId + "receiveUserId");
    console.log(publishId + "publishId")
    console.log(index);
    this.setData({
      receiveUserIdArray: receiveUserIdArray
    })
    var that = this;
    if (status <= 4 && that.data.receiveUserIdArray.length == 0) {
      wx.navigateTo({
        url: '../masterList/masterList?userId=' + publishId + "&receiveUserIdArray=" + array,
      })

    } else if (status <= 4 && that.data.receiveUserIdArray.length > 0) {
      wx.navigateTo({
        url: '../masterList/masterList?userId=' + publishId + "&receiveUserIdArray=" + array,
      })
    } else if (status > 4) {
      wx.navigateTo({
        url: '../servering/servering?userId=' + index + "&receiveUserId=" + receiveUserId
      })
      wx.setStorageSync("orderDetailId", index)
    }

  },
//  禁止苹果下拉测试
  onPageScroll: function (e) {
    if (e.scrollTop < 0) {
      wx.pageScrollTo({
        scrollTop: 0
      })
    }
  },
  swiper(e){
    var current=e.detail.current;
    console.log(current);
    this.setData({
      currentTabsIndex:current
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    setTimeout(() => {
      this.setData({
        show: true
      });
    }, 500);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
   this.myData();
    this.animation = wx.createAnimation();
  },

  inputText: function (e) {
    let that = this;
    // console.log(e);
    that.setData({
      inputText: e.target.dataset.name
    })

  },

  text: function (e) {
    let that = this;
    // console.log(e);
    that.setData({
      text: e.target.dataset.text
    })
  },
  itemTap: function (e) {
    var index = e.currentTarget.dataset.index;
    console.log(index);
    this.setData({
      currentTabsIndex: index,
      current:index
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  myData:function(){
   
    var that = this;
    if (that.data.orderList == '' || that.data.orderList == undefined || that.data.orderList == null){
      wx.showLoading({
        title: '加载中...',
      })
    }


    wx.request({
      url: 'https://www.xiaozheng8.com/serviceOrder/sendFindUnFinish',
      method: "post",
      data: {
        userId: wx.getStorageSync("userId"),
      },
      success: function (res) {
        console.log(res.data.data);
        that.setData({
          orderList: res.data.data
        });
        for (var i = 0; i < that.data.orderList.length; i++) {
          if (that.data.orderList[i].isCancel == true) {
            that.data.orderList.splice(i, 1);
          }
        }
        that.setData({
          orderList: that.data.orderList
        })
   
      
      }

    }),
      wx.request({
        url: 'https://www.xiaozheng8.com/serviceOrder/sendFindFinish',
        method: "post",
        data: {
          userId: wx.getStorageSync("userId"),
        },
        success: function (res) {
          console.log(res);
          that.setData({
            finishList: res.data.data
          })
          console.log(res.data.data);
        
        }

      });
    if (this.data.orderList.length == 0) {
      wx.hideLoading();
    }
  
  },
  onPullDownRefresh: function () {
    this.myData();
    setTimeout(() => {
      wx.stopPullDownRefresh()
    }, 2000)
  }
})